import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[],
  },
  getters: {
    unFinishCount(state){
      var arr=state.list.filter((item)=>{
        return item.status==false;
      })
      return arr.length;
    }
  },
  mutations: {
    addTask(state,payload){
      var obj={id:state.list.length+1,name:payload,status:false};
      state.list.push(obj);
    },
    changeStatus(state,payload){
      var fi=state.list.find((item)=>{
        return item.id==payload.id
      })
      if(fi){
        fi.status=!fi.status;
      }
    },
    delete(state,payload){
      state.list.splice(payload.id-1,1);
      for(let i=0; i<state.list.length; i++){
        for(let index in state.list[i]){
            state.list[i].id = i+1;
        }
    }
    }
  },
  actions: {
  },
  modules: {
  }
})
